/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main.LanguageResource;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 *
 * @author Isaac Osesina
 */
public class DefaultPhraseSynthesizer extends AbstractPhraseSynthesizer<LocalPOS>{
    
    private LocalPOSFactory factory;
    
    public DefaultPhraseSynthesizer(LocalPOSFactory factory, POS_Tagger<LocalPOS> posTagger, Dictionary<LocalPOS> dictionary) {
        super(posTagger, dictionary);
        this.factory = factory;
    }
    
    
    @Override
    public Set<String> synthesize(String phrase) {
        if(getDictionary()==null)
            return null;
        List<WordConstruct<LocalPOS>> taggedWords = getPosTagger().tagPOS(factory, phrase);        
        if(taggedWords == null)
            return null;
        List<Set<String>> wordSet = new ArrayList<Set<String>>();
        for(WordConstruct<LocalPOS> wc:taggedWords) {
            if(wc==null)
                continue;
            Set<String> synonyms = null;
//            if(wc.getPOS() != null && wc.getPOS().getValue().startsWith("VB")) 
            {
                synonyms = this.getSynonyms(wc);
                if(synonyms == null) {
                    synonyms = getDictionary().getSynonyms(wc.getWord(), wc.getPOS());
                    this.addSynonyms(wc, synonyms);
                }
            }

            if(synonyms == null || synonyms.isEmpty()) {
                synonyms = new HashSet<String>();
                synonyms.add(wc.getLemma()==null ? wc.getWord():wc.getLemma());
            }
            wordSet.add(synonyms);
        }
        return this.generateStringCombinations(wordSet);
    }
    
    

    
}
